﻿using System;
using Twitter;

namespace TemperatureBots
{
	public class FahrenheitToCelsiusGreeting : IGreeter
	{
		public void Greet(IBotClient botClient, string newFriend)
		{
			botClient.Messages.Send(newFriend, String.Format("Hello {0}, this is the friendliest F2C bot! Just send 'D F2C 95' and you'll get '35'", newFriend));
		}
	}

	public class FahrenheitToCelsiusMessageProcessor : IMessageProcessor
	{
		public RunNextProcessor Process(IBotClient botClient, Message message)
		{
			double f = Convert.ToDouble(message.Text);
			double c = (5d / 9d) * (f - 32);

			botClient.Messages.Send(message.Sender.ScreenName, string.Format("{0} fahrenheit is {1} celsius!", f, c));

            return RunNextProcessor.Yes;
		}

		public bool CanProcess(Message message)
		{
			// Can only process the message if it contains a valid double value.
			double value;
			return double.TryParse(message.Text, out value);
		}
	}
}
